package com.summer.ChengXuYuanMianShiJingDian;

import com.summer.ListNode;

public class Q2_4 {
    public static ListNode partition(ListNode head, int x) {
        if (head==null||head.next==null) return head;
        ListNode node = head;
        while (!isline(head,x)){
            change(head,x);
        }
        return head;
    }
    public static ListNode change(ListNode head , int x){
        ListNode node = head;
        while (node.next!=null){
            if(node.val>=x&&node.next.val<x) {
                int temp = node.next.val;
                node.next.val = node.val;
                node.val = temp;
            }
            node = node.next;
        }
        return head;
    }
    public static boolean isline(ListNode head,int x){
        ListNode node = head;
        boolean flag = true;
        while (node.next!=null){
            if(node.val>=x&&node.next.val<x) {
                flag = false;
                break;
            }
            node = node.next;
        }
        return flag;
    }
}
